//SUMMARY:  This do file replicates findings in "Trade as Villain" from the Yougov experiment

clear all
set more off

*Set classpath here:
cd "XXX"

use "YG experiment replication data.dta", clear

*Define control variables:
global controls "age female i.educ4 ib4.race4 hasChild isMarried ib4.income3"

//TABLE 1: Descriptive statistics
gen isWhite = (race4 == 1) if race4 != .
label var isWhite "White"
gen isBlack = (race4 == 2) if race4 != .
label var isBlack "Black"
gen isHispanic = (race4 == 3) if race4 != .
label var isHispanic "Hispanic"
gen isOther = (race4 == 4) if race4 != .
label var isOther "Other"
gen hsLess = (educ4 == 1) if educ4 != .
label var hsLess "HS or less"
gen someCollege = (educ4 == 2) if educ4 != .
label var someCollege "Some college"
gen college = (educ4 == 3) if educ4 != .
label var college "College"
gen postGrad = (educ4 == 4) if educ4 != .
label var postGrad "Post-grad"
gen inclt50k = (income3 == 1) if income3 != .
label var inclt50k "Inc. <$50k"
gen inc50_100k = (income3 == 2) if income3 != .
label var inc50_100k "Inc. $50-100k"
gen incgt100k = (income3 == 3) if income3 != .
label var incgt100k "Inc. >$100k"
gen incNotSay = (income3 == 4) if income3 != .
label var incNotSay "Inc. not reported"

estpost tabstat age female isWhite isBlack isHispanic isOther hsLess someCollege college postGrad inclt50k inc50_100k incgt100k incNotSay isDemoc isRepub isIndep avgUS, by(poorLazy) columns(statistics) nototal
esttab ., cells(mean(fmt(3))) label unstack tex

//TABLE 2:  AD vs IQ framing effect
reg expandTrade dreamTreat  [pweight=weight]
outreg2 using "Output\baseline_YGexp", replace tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg reduceImmig dreamTreat [pweight=weight]
outreg2 using "Output\baseline_YGexp", append tex(fra) ctitle(Reduce Immigration) nocons bdec(3) label

//FIGURE 1:  Trade preferences by treatment X meritocracy
reg expandTrade dreamTreat##poorLazy $controls [pweight=weight]
margins poorLazy, at(dreamTreat = 1) post
est sto treated
reg expandTrade dreamTreat##poorLazy $controls [pweight=weight]
margins poorLazy, at(dreamTreat = 0) post
est sto control
coefplot (treated, label(AD frame)) (control, label(IQ frame)), recast(bar) bycoefs vertical barwidth(.3) bargap(-10) fcolor(*.5) ciopts(recast(rcap)) citop format(%9.2f) ytitle(Expand trade) xlabel("")
graph export "Output\AD_effect(by_meritocracy).png", as(png) replace

//FIGURE 2:  Trade preferences by treatment X social mobility X meritocracy
reg expandTrade dreamTreat##poorLazy##childWorse $controls [pweight=weight]
margins poorLazy#childWorse, at(dreamTreat == 0) post
est sto controlMeritXchild
reg expandTrade dreamTreat##poorLazy##childWorse $controls [pweight=weight]
margins poorLazy#childWorse, at(dreamTreat == 1) post
est sto treatMeritXchild
coefplot (treatMeritXchild, label("AD frame")) (controlMeritXchild, label("IQ frame")), bycoefs recast(bar) byopts(title("Views on trade (social mobility X meritocracy beliefs)")) vertical coeflabels(, interaction(" x ")) barwidth(.3) bargap(-10) fcolor(*.5) ciopts(recast(rcap)) citop format(%9.2f) ytitle(Expand trade) xlabel("") 

//TABLE 3:  Partisanship, Blame & Trade
reg expandTrade dreamTreat##poorLazy $controls i.isRepub isDemoc [pweight=weight]
outreg2 using "Output\partisanship", replace tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy dreamTreat##i.isRepub $controls isDemoc [pweight=weight]
outreg2 using "Output\partisanship", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy i.isConservative $controls  [pweight=weight]
outreg2 using "Output\partisanship", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy dreamTreat##i.isConservative $controls   [pweight=weight]
outreg2 using "Output\partisanship", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy $controls i.trumpVoter  [pweight=weight]
outreg2 using "Output\partisanship", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy dreamTreat##i.trumpVoter $controls  [pweight=weight]
outreg2 using "Output\partisanship", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label

* APPENDIX RESULTS
//TABLE A5:  AD vs IQ frame, with controls
reg expandTrade dreamTreat##poorLazy $controls [pweight=weight]
outreg2 using "Output\controls_YGexp", replace tex(fra) ctitle(Expand Trade) nocons bdec(3) label
reg expandTrade dreamTreat##poorLazy##childWorse $controls [pweight=weight]
outreg2 using "Output\controls_YGexp", append tex(fra) ctitle(Expand Trade) nocons bdec(3) label

//TABLE A7:  Threats to American Dream
reg dream_trade poorLazy age female ib4.race4 i.educ4 i.income3 [pweight=weight]
outreg2 using "Output\americanDream", replace tex(fra) ctitle(Trade harms AD) nocons bdec(3) label
reg dream_educa poorLazy age female ib4.race4 i.educ4 i.income3 [pweight=weight]
outreg2 using "Output\americanDream", append tex(fra) ctitle(Educ. harms AD) nocons bdec(3) label
reg dream_discr poorLazy age female ib4.race4 i.educ4 i.income3 [pweight=weight]
outreg2 using "Output\americanDream", append tex(fra) ctitle(Discr. harms AD) nocons bdec(3) label

//Balance table for IME
estpost tabstat age female isWhite isBlack isHispanic isOther hsLess someCollege college postGrad inclt50k inc50_100k incgt100k incNotSay isDemoc isRepub isIndep avgUS, by(childWorse) columns(statistics) nototal
esttab ., cells(mean(fmt(3))) label unstack tex
